<script>
function onprofileOpen() {
    refreshGrid("profiles");
}
</script>

<table>
<tr><td>
<table id="profiles" class="admingrid">
</table>
<div id="profiles_pager"></div>
</td><td valign="top">
<div style="display:none;" id="profile_accept_form" class="adminform">
    <button name="acceptchanges" id="" onclick="acceptProfileChanges(this)">Accept changes</button>
    <button name="rejectchanges" id="" onclick="rejectProfileChanges(this)">Reject changes</button>
    <button name="preview" id="" onclick="previewProfile(this)">Preview new profile</button>
</div>
</td></tr>
</table>

<script>
grids.profiles = {
    url : generateServiceUrl({
        admin : true,
        service : "getprofilelist",
        page : "confirm"
    }),
    colNames : [
        "company_name"
    ],
    colModel : [
        { name : "company_name",   index : "company_name",   width : 350 },
    ],
    caption : "Company list"
};

function profiles_selected(id) {
    jQuery("table#changelist").empty();
    callAdminService("confirm", "getchanges", {
        type : "profile",
        id : id
    }, {
        success : function(result) {
            jQuery("button[name='acceptchanges']").attr("id", id);
            jQuery("button[name='rejectchanges']").attr("id", id);
            jQuery("button[name='preview']").attr("id", id);
            jQuery("#profile_accept_form").show("fade", {}, 300);
            for (var change in result.data) {
                if (typeof(result.data[change]) == "function") { continue; }
                if (typeof(window["profile_" + change + "_display"]) == "function") {
                    var displayData = eval("profile_" + change + "_display(result.data[change])");
                    jQuery("table#changelist").append(
                        jQuery("<tr>").append(
                            jQuery("<td>")
                                .text(displayData[0] + ": ")
                        ).append(
                            jQuery("<td>")
                                .text(displayData[1])
                        )
                    );
                }
            }
        }
    });
}

function profile_hpenglish_display(value) { return ["English homepage", value]; }
function profile_hphungarian_display(value) { return ["Hungarian homepage", value]; }
function profile_companyname_display(value) { return ["Company name", value]; }

function acceptProfileChanges(item) {
    callAdminService("confirm", "acceptchanges", {
        type : "profile",
        id : item.id
    }, {
        success : function(result) {
            jQuery("#profile_accept_form").hide("fade", {}, 300);
            refreshGrid("profiles");
        }
    });
}

function rejectProfileChanges(item) {
    callAdminService("confirm", "rejectchanges", {
        type : "profile",
        id : item.id
    }, {
        success : function(result) {
            jQuery("#profile_accept_form").hide("fade", {}, 300);
            refreshGrid("profiles");
        }
    });
}

function previewProfile(item) {
    callHtmlService("companyprofile", "view", {
        type : "profile",
        id : item.id,
        displayType : "preview"
    }, {
        success : function(html) {
            openOverlay(700, 400, html);
        }
    });
}

</script>

